/**
 * 现金收费——返利收费
 * @author shuang
 * @date 2021/12/12 23:52
 */
public class CashReturn extends CashSuper {
    /**
     * 返利条件
     */
    private double moneyCondition = 0.0d;

    /**
     * 返利条件相应的返利点
     */
    private double moneyReturn = 0.0d;

    /**
     * 初始化时指定返利条件及返利点，如满 300 返 100
     * @param moneyCondition 返利条件
     * @param moneyReturn 返利点
     */
    public CashReturn(String moneyCondition, String moneyReturn) {
        this.moneyCondition = Double.parseDouble(moneyCondition);
        this.moneyReturn = Double.parseDouble(moneyReturn);
    }

    @Override
    public double acceptCash(double money) {
        double result = money;
        if (result >= moneyCondition) {
            // 满 300 返 100，则 900 时需要返 300
            result -= Math.floor(result / moneyCondition) * moneyReturn;
        }
        return result;
    }
}

